package com.egg.ylt.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.Utils.CustomUtils;
import com.egg.ylt.Utils.StatusBarUtil;
import com.egg.ylt.Utils.StringUtil;
import com.egg.ylt.adapter.ADA_IntegralRecycler;
import com.egg.ylt.pojo.IntegralFlowEntity;
import com.egg.ylt.presenter.impl.IntegralPresenterImpl;
import com.egg.ylt.view.IIntegralView;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.utils.AppSharedPreferences;
import com.yonyou.framework.library.common.utils.ListUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class ACT_Integral extends BaseActivity<IntegralPresenterImpl> implements IIntegralView {

    @BindView(R.id.include_iv_back)
    ImageView includeIvBack;
    @BindView(R.id.include_tv_title)
    TextView includeTvTitle;
    @BindView(R.id.include_tv_right)
    TextView includeTvRight;
    @BindView(R.id.include_rl_view)
    RelativeLayout includeRlView;
    @BindView(R.id.tv_num_integral)
    TextView tvNumIntegral;
    @BindView(R.id.recycler_integral)
    RecyclerView recyclerIntegral;
    @BindView(R.id.target_view_ll)
    LinearLayout llTargetView;

    private ADA_IntegralRecycler adaIntegralRecycler;
    private AppSharedPreferences mSp;
    private String mToken;

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_integral;
    }

    @Override
    protected View getLoadingTargetView() {
        return llTargetView;
    }

    @Override
    protected void initViewsAndEvents() {

        StatusBarUtil.setStatusBarColor(this, R.color.ylt_whit);
        StatusBarUtil.StatusBarLightMode(this);
        CustomUtils.setImmersiveStatusBar(mContext, includeRlView);
        //设置title
        includeTvTitle.setText("积分");

        //获取本地用户token
        mSp = new AppSharedPreferences(mContext);
        mToken = mSp.getString(Constants.USER_TOKEN);

        //初始化recycle
        initRecyclerView();
    }

    private void initRecyclerView() {
        //设置布局管理器
        recyclerIntegral.setLayoutManager(new LinearLayoutManager(mContext));
        //设置适配器
        adaIntegralRecycler = new ADA_IntegralRecycler(mContext);
        recyclerIntegral.setAdapter(adaIntegralRecycler);

        //请求会员积分数据
        mPresenter.getIntegralData(Constants.TOKEN, Constants.COMPANYID, "1", "50");
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }

    @OnClick({R.id.include_iv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.include_iv_back://返回键
                finish();
                break;
        }
    }

    @Override
    public void getIntegral(IntegralFlowEntity entity) {
        if (entity != null && !StringUtil.isEmpty(entity.getId())) {
            //设置用户积分
            tvNumIntegral.setText(entity.getIntegral());
        }

        if (ListUtil.isListEmpty(entity.getList())) {
            toggleShowEmpty(true, R.drawable.empty_no_response, "暂无积分消费信息");
            return;
        }

        toggleShowEmpty(false, -1, "");

        // 设置数据
        adaIntegralRecycler.setmList(entity.getList());
    }
}
